package offerbook;

/**
 * @date 2020/3/12 16:57
 */
public class Code52_MultiArr_数组乘积 {
    public int[] multiply(int[] A) {
        if(A == null || A.length <=0) return null;
        int[]B = new int[A.length];
        //先计算下三角
        B[0] = 1;
        for (int i = 1; i < A.length; i++) {
            B[i] = B[i-1] *A[i-1];
        }
        //再计算上三角
        int temp = 1;
        for (int i = A.length-2; i >= 0 ; i--) {
            temp = temp * A[i+1];
            B[i] = B[i] * temp;
        }
        return B;
    }
}
